{% extends 'base_backend.html' %}
{% load static %}
{% load my_filter %}

{% block header_tail %}
    <link rel="stylesheet" href="{% static 'zhongbao/zhongbao_admin/css/style.css' %}">
    <link rel="stylesheet" href="{% static 'zhongbao/zhongbao_admin/css/iconfont.css' %}">
    <link rel="stylesheet" href="{% static 'plugins/datatables/dataTables.bootstrap.css' %}">
    <link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
    <link rel="stylesheet" href="{% static 'zhongbao/config/css/main.css' %}">
    <link rel="stylesheet" href="{% static 'laydate/theme/default/laydate.css' %}">
    <script src="{% static 'laydate/laydate.js' %}"></script>
    <script src="{% static 'plugins\jQuery\jquery-2.2.3.min.js' %}"></script>

    <script src="{% static 'plugins/vue1/vue.js' %}"></script>

    <style>
        .login-banner {
            width: 100%;
            background: url("{% static 'public/img/banner2.jpg' %}") center bottom/cover no-repeat;
        }
    </style>
{% endblock header_tail %}

{% block section_content %}

    {% if manage_type != 'project_spot_check_admin' %}
        {% include 'maintain/base_maintain_statistics.html' %}
    {% endif %}

    <div>
        <!--  任务自动分配及手动分配功能  -->
        {% if manage_type == 'task_pools_admin' %}
            <!--手动分配start-->
            <div class="row">
                <div class="col-md-12">
                    <!-- DIRECT CHAT -->
                    <div class="box box-primary direct-chat direct-chat-primary collapsed-box">
                        <div class="box-header with-border">
                            <h3 class="box-title">手动分配</h3>
                            <div class="box-tools pull-right">
                                <span data-toggle="tooltip" title="{{ communicatesNum }} Messages"
                                      class="badge bg-blue">{{ review_log_count }}</span>
                                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i
                                        class="fa fa-plus"></i>
                                </button>
                            </div>
                        </div>
                        <div class="box-body">
                            <form action="{% url 'maintain:manual_allot' %}" method="post">
                                {% csrf_token %}
                                <div style="width: 95%; float: left;">
                                    {% for agency in auto_allot_agency_list %}
                                        <div class="input-group select-config-div" style="float: left; ">
                                            <label for="" class="control-label">{{ agency.agent_name }}：</label>
                                            <p>
                                                <input type="text" name="{{ agency.id }}" autocomplete="off"
                                                       value="" placeholder="分配项目数"
                                                       class="config-input">
                                            </p>
                                        </div>
                                    {% endfor %}
                                    <div style="float: left;" class="input-group select-config-div">
                                        <label for="ptask_num" class="control-label">单个项目任务量：</label>
                                        <p>
                                            <input type="text" name="ptask_num" autocomplete="off" value=""
                                                   placeholder="项目任务量" class="config-input">
                                        </p>
                                    </div>
                                </div>
                                <div class="input-group" style="width: 5%; float: right; margin-top: 70px;">
                                    <input type="submit" class="form-control pull-left btn btn-sm btn-primary">
                                </div>
                                <p style="clear: both"></p>
                                <div class="form-group">
                                </div>
                            </form>
                        </div>

                        <div class="box-footer">
                            <div class="input-group">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--手动分配end-->
            <!--自动分配start-->
            <div class="row">
                <div class="col-md-12">
                    <!-- DIRECT CHAT -->
                    <div class="box box-primary direct-chat direct-chat-primary collapsed-box">
                        <div class="box-header with-border">
                            <h3 class="box-title">自动分配</h3>
                            <div class="box-tools pull-right">
                                <span data-toggle="tooltip" title="{{ communicatesNum }} Messages"
                                      class="badge bg-blue">{{ review_log_count }}</span>
                                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i
                                        class="fa fa-plus"></i>
                                </button>
                            </div>
                        </div>
                        <div class="box-body">
                            <form action="{% url 'maintain:auto_allot_set' %}" method="get">
                                <div style="width: 95%; float: left;">
                                    {% for agency in auto_allot_agency_list %}
                                        <div class="input-group select-config-div" style="float: left; ">
                                            <label for="" class="control-label">{{ agency.agent_name }}：</label>
                                            <p>
                                                <input type="text" name="{{ agency.id }}" autocomplete="off"
                                                       value="{{ agency.id|main_auto_allot }}" placeholder="分配项目数"
                                                       class="config-input">
                                            </p>
                                        </div>
                                    {% endfor %}
                                    <div style="float: left;" class="input-group select-config-div">
                                        <label for="id" class="control-label">自动分配(1-启动，0-停止)：</label>
                                        <p>
                                            <input type="text" name="swith" autocomplete="off" value="{{ swith }}"
                                                   placeholder="分配数量" class="config-input">
                                        </p>
                                    </div>
                                </div>
                                <div class="input-group" style="width: 5%; float: right; margin-top: 70px;">
                                    <input type="submit" class="form-control pull-left btn btn-sm btn-primary">
                                </div>
                                <p style="clear: both"></p>
                                <div class="form-group">
                                </div>
                            </form>
                        </div>
                        <div class="box-footer">
                            <div class="input-group">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--自动分配end-->
        {% endif %}
        <div class="box-header with-border">
            <h3 class="box-title">{{ model_verbose_name }}</h3>
        </div>
        <!-- form start -->
        <div class="box box-primary">
            {% if manage_type != 'project_spot_check_admin' %}
                <div class="box-header with-border" style="border-color: #1b6d85">
                    <!-- Date range -->
                    <form role="form" id="searchForm">
                        <input class="no-display" type="text">
                        <p style="clear: both"></p>
                        <div style="width: 95%; float: left;">
                            {% for field in form %}
                                <div class="input-group select-config-div" style="float: left; ">
                                    <label for="" class="control-label">{{ field.label }}：</label>
                                    <p>{{ field }}</p>
                                </div>
                            {% endfor %}
                            <div style="float: left;" class="input-group select-config-div">
                                <label for="id" class="control-label">任务状态：</label>
                                <select name="status_id" id="taskStatus" class="config-input">
                                    <option selected="selected" value="">全部</option>
                                    {% for status in status_list %}
                                        {% if status.id == status_id %}
                                            <option selected="selected"
                                                    value="{{ status.id }}">{{ status.description }}</option>
                                        {% else %}
                                            <option value="{{ status.id }}">{{ status.description }}</option>
                                        {% endif %}
                                    {% endfor %}
                                </select>
                            </div>
                            <!-------------新添加---------------->
                            <div style="float: left;" class="input-group select-config-div">
                                <label for="id" class="control-label">任务不合格次数：</label>
                                <p>
                                    <input id="disqualify_num" name="disqualify_num" type="number" class="config-input">
                                </p>
                            </div>
                            <div style="float: left;" class="input-group select-config-div">
                                <label for="id" class="control-label">是否提交质检：</label>
                                <select name="is_submit_quality" id="is_submit_quality" class="config-input">
                                    <option selected="selected" value="">全部</option>
                                    <option value="True">是</option>
                                    <option value="False">否</option>
                                </select>
                            </div>

                            <div style="float: left;" class="input-group select-config-div">
                                <label for="id" class="control-label">任务优先级：</label>
                                <select name="priority" id="priority" class="config-input">
                                    <option selected="selected" value="">全部</option>
                                    <option value="特急">特急</option>
                                    <option value="高级">高级</option>
                                    <option value="中级">中级</option>
                                    <option value="低级">低级</option>
                                </select>
                            </div>
                            <div style="float: left;" class="input-group select-config-div">
                                <label for="id" class="control-label">不合格原因：</label>
                                <select name="disqualify_reason_new" id="disqualify_reason_new" class="config-input">
                                    <option selected="selected" value="">全部</option>
                                    <option value="备案号未填写">备案号未填写</option>
                                    <option value="代码错误">代码错误</option>
                                    <option value="配置分组错误">配置分组错误</option>
                                    <option value="配置编码">配置编码</option>
                                    <option value="采集时限错误">采集时限错误</option>
                                    <option value="info_flag错误">info_flag错误</option>
                                    <option value="国家错误">国家错误</option>
                                    <option value="语言错误">语言错误</option>
                                    <option value="域名错误">域名错误</option>
                                    <option value="url错误">url错误</option>
                                    <option value="title错误">title错误</option>
                                    <option value="ctime错误">ctime错误</option>
                                    <option value="source错误">source错误</option>
                                    <option value="source_id错误">source_id错误</option>
                                    <option value="retweeted_source错误">retweeted_source错误</option>
                                    <option value="retweeted_status_url错误">retweeted_status_url错误</option>
                                    <option value="channel错误">channel错误</option>
                                    <option value="pic_urls错误">pic_urls错误</option>
                                    <option value="sitename错误">sitename错误</option>
                                    <option value="visitCount错误">visitCount错误</option>
                                    <option value="replyCount错误">replyCount错误</option>
                                    <option value="content错误">content错误</option>
                                    <option value="content_xml错误">content_xml错误</option>
                                    <option value="audio_urls错误">audio_urls错误</option>
                                    <option value="video_urls错误">video_urls错误</option>
                                    <option value="face_img错误">face_img错误</option>
                                    <option value="is_junk错误">is_junk错误</option>
                                    <option value="网站名称内外不一致">网站名称内外不一致</option>
                                    <option value="其他">其他</option>
                                </select>
                            </div>
                            <!---------------新添加end------------------>
                            <div style="float: left;" class="input-group select-config-div">
                                <label for="id" class="control-label">每页显示：</label>
                                <select name="limit" id="showNumSelect" class="config-input">
                                    {% for i in limits %}
                                        {% if i == limit %}
                                            <option selected="selected" value="{{ i }}">{{ i }}条</option>
                                        {% else %}
                                            <option value="{{ i }}">{{ i }}条</option>
                                        {% endif %}
                                    {% endfor %}
                                </select>
                            </div>
                            {% if user.is_superuser %}
                                <div style="float: left;" class="input-group select-config-div">
                                    <label for="id" class="control-label">代理机构：</label>
                                    <select name="agency_id" class="config-input">
                                        <option selected="selected" value="">---------</option>
                                        {% for agency in agency_list %}
                                            {% if agency.id == agency_id %}
                                                <option selected="selected"
                                                        value="{{ agency.id }}">{{ agency.agent_name }}</option>
                                            {% else %}
                                                <option value="{{ agency.id }}">{{ agency.agent_name }}</option>
                                            {% endif %}
                                        {% endfor %}

                                    </select>
                                </div>
                            {% endif %}
                            <div class="input-group" style="width: 5%; float: left; ">
                                <input type="text" class="no-display">
                                <span id="searchBtn" onclick="searchTasks()"
                                      class="form-control pull-left btn btn-sm btn-primary"
                                      style="margin-top:20px;width: 50px">检索
                                            </span>
                            </div>
                            <div class="input-group" style="width: 5%; float: left; ">
                               <span id="searchBtn" onclick="maintain_task_download()"
                                     class="form-control pull-left btn btn-sm btn-primary"
                                     style="margin-top:20px;width: 50px">下载
                                            </span>
                            </div>
                        </div>

                        <p style="clear: both"></p>
                        <div class="form-group">
                        </div>
                    </form>
                </div>
            {% endif %}
            <!-- 展示搜索出来的任务 -->
            <div id="main">
                <!--抽检结果-->
                <div class="modal fade" id="spot_check_result" tabindex="-1" role="dialog"
                     aria-labelledby="myModalLabel"
                     style="top:40%">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div id="SpotMsgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                                通过数量：[[ spot_check_info.qualified_count ]]
                                <br>
                                不合格数量：[[ spot_check_info.unqualified_count ]]
                            </div>
                            <div class="modal-footer" style="text-align:center;">
                                <button type="button" class="btn btn-default" onclick="pass_all()" data-dismiss="modal">
                                    全部通过
                                </button>
                                <button type="button" class="btn btn-default" data-dismiss="modal">
                                    取消
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <div id="showMessage" v-show="message"> [[ message ]]</div>
                <div class="box-body" v-show="showMain">
                    <form id="model_form" role="form" method="post">
                        {% csrf_token %}
                        <div class="group">
                            {% if manage_type == 'task_pools_admin' %}
                                <button style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                        onclick="verify_batch(0)">创建项目
                                </button>
                                <button style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                        onclick="verify_batch(1)">添加到项目
                                </button>
                            {% elif manage_type == 'task_allot_admin' or manage_type == 'task_allot_agent' %}
                                <button style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                        data-toggle="modal" data-target="#userList">分配任务
                                </button>
                            {% elif manage_type == 'project_spot_check_admin' %}
                                <button style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                        data-toggle="modal" data-target="#spot_check">刷新抽检
                                </button>
                                <button style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                        data-toggle="modal" data-target="#spot_check_result">查看抽检结果
                                </button>
                            {% endif %}
                            <span>共<b>[[ paginator.total ]]</b>个 </span>
                            {% if request.user.is_agent %}
                                <span>查询共[[ paginator.total ]]笔，你可以全选或勾选任务,建议20及以上笔任务提交质检</span>
                                <span class="btn btn-info btn-xs" onclick="submit_inspection()">提交质检</span>
                            {% endif %}
                            <!--任务列表--start-->
                            <table id="task_each_table" border="1"
                                   class="table table-bordered table-hover table-striped">
                                <thead>
                                <tr>
                                    <th class="action-checkbox">
                                        <input type="checkbox" name="th_checkbox_all" onclick="checkAll(this)">
                                    </th>
                                    <th v-for="head in tableData.headers">
                                        <span style="float: left">
                                            [[ head.name ]]
                                        </span>
                                        {% if field.rank %}
                                            <a href="?[[ head.rank ]]=[[ head.rank_tag ]][[ page_args ]]"
                                               style="float: right">
                                                {% if field.rank_tag == 0 %}
                                                    <i class="fa fa-fw fa-sort"></i>
                                                {% elif field.rank_tag == 1 %}
                                                    <i class="fa fa-fw fa-sort-numeric-asc"></i>
                                                {% elif field.rank_tag == -1 %}
                                                    <i class="fa fa-fw fa-sort-numeric-desc"></i>
                                                {% endif %}
                                            </a>
                                        {% endif %}
                                    </th>
                                    <th>
                                    <span style="float: left">
                                        操作
                                    </span>
                                    </th>
                                </tr>
                                </thead>
                                <tbody>
                                <template v-for="task in tableData.tasks">
                                    <tr>
                                        <td class="action-checkbox">
                                            <input type="checkbox" name="td_checkbox" class="[[ task.batch ]]"
                                                   status_id="[[ parseStatus(task.status) ]]"
                                                   value="[[ task.id ]]" onclick="checkOne(this)">
                                        </td>
                                        <template v-for="head in tableData.headers">
                                            <template v-if="head.key.indexOf('flag') != -1 || head.key == 'ctime'">
                                                <td>[[ parseTime(task[head.key]) ]]</td>
                                            </template>
                                            <template v-else>
                                                <td v-if="head.key == 'status'">[[ parseStatus(task[head.key]) ]]</td>
                                                <td v-else title="[[ task[head.key] ]]">[[ truncatechars(task[head.key],
                                                    10) ]]
                                                    <span v-if="head.key == 'disqualify_reason_new' && [[ task[head.key] ]] != ''"
                                                          id="copy_button"
                                                          style="background: #d2c3c3; font-size: 2px; cursor: pointer"
                                                          onclick="copy_text('[[ task[head.key] ]]')">复制</span>
                                                </td>
                                            </template>
                                        </template>
                                        <td class="btn-group">
                                            {% if user.is_superuser == 1 or user.is_agent == 1 %}

                                                <a class="btn btn-info btn-xs"
                                                   href="{{ task_detail_url }}?task_id=[[task.id]]">详情</a>
                                            {% else %}
                                                <a class="btn btn-info btn-xs"
                                                   v-show="task.is_distort != 1 && task.is_distort != 2"
                                                   href="{{ task_detail_url }}?task_id=[[task.id]]">详情</a>
                                            {% endif %}
                                            {% if manage_type == 'task_manage_admin' or manage_type == 'task_manage_agent' or 'project_detail' in manage_type %}
                                                <a v-show="[4,6].indexOf(task.status) != -1" class="btn btn-info btn-xs"
                                                   onclick="BubbleTooltip('qualified', '[[ task.id ]]')">合格</a>
                                                <a v-show="[4,5,14].indexOf(task.status) != -1"
                                                   class="btn btn-info btn-xs"
                                                   onclick="BubbleTooltip('disqualified', '[[ task.id ]]')">不合格</a>
                                                <a v-show="[3,6].indexOf(task.status) != -1" class="btn btn-info btn-xs"
                                                   onclick="BubbleTooltip('recycle', '[[ task.id ]]')">回收</a>
                                            {% endif %}
                                            {% if manage_type == 'task_manage_admin' %}
                                                <a v-show="[5].indexOf(task.status) != -1" class="btn btn-info btn-xs"
                                                   onclick="BubbleTooltip('pass', '[[ task.id ]]')">通过</a>
                                            {% endif %}
                                            {% if user.is_superuser %}
                                                <a class="btn btn-info btn-xs"
                                                   href="{% url 'maintain:operating_record' 'task' %}?id=[[task.id]]">操作记录</a>
                                            {% endif %}
                                        </td>
                                    </tr>
                                </template>
                                </tbody>
                            </table>
                            <!--任务列表--end-->
                            <!-- 翻页 --start -->
                            <p class="" id="paginator">
                                <a class="btn btn-default btn-xs" v-if="paginator.current > 1"
                                   onclick="toPage('first')">首页</a>
                                <a class="btn btn-default btn-xs" v-else disabled="true">首页</a>
                                <a class="btn btn-default btn-xs" v-if="paginator.current > 1"
                                   onclick="toPage('prev')">上一页</a>
                                Page [[ paginator.current ]] of [[ paginator.last ]]
                                <span v-show="paginator.total">共[[ paginator.total ]]个</span>
                                <a class="btn btn-default btn-xs" v-if="paginator.current < paginator.last"
                                   onclick="toPage('next')">下一页</a>
                                <a class="btn btn-default btn-xs" v-if="paginator.current < paginator.last"
                                   onclick="toPage('last')">尾页</a>
                                <a class="btn btn-default btn-xs" v-else disabled="true">尾页</a>
                                <input type="text" id="page-judge" style="width: 30px;height:20px; margin-left: 20px"
                                       onkeyup="toPage('judge')">
                                <a class="btn btn-default btn-xs" onclick="toPage('judge')">跳页</a>
                            </p>
                            <!-- 翻页 --end -->
                        </div>
                        <!-- /.box-footer -->
                        <div class="box-footer">
                            <button class="btn btn-primary no-display" id="submit_button">确认</button>
                            <button type="button" class="btn btn-primary" id="save_submit" name="_save"
                                    style="display: none">sure
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!--用户列表，任务分配-->
    <div class="modal fade" id="userList" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="overflow: hidden; ">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>请选择要分配给谁：</label>
                </div>
                <div class="modal-body" style="overflow-y: scroll; max-height: 500px;">
                    <table id="user_each_table" border="1" class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th class="action-checkbox">
                            </th>
                            <th>
                            <span style="float: left">
                                用户名
                            </span>
                            </th>
                            <th>
                            <span style="float: left">
                                姓名
                            </span>
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for user in user_list %}
                            <tr>
                                <td class="action-checkbox">
                                    <input type="radio" name="uid_radio" value="{{ user.id }}">
                                </td>
                                <td>{{ user.username }}</td>
                                <td>{{ user.real_name }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" id="confirm_close" class="btn btn-default" data-dismiss="modal"
                            onclick="allocate()">
                        确认
                    </button>
                    <button type="button" id="cancel_close" class="btn btn-default" data-dismiss="modal">
                        取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!--创建项目弹出框-->
    <div class="modal fade" id="createProjectMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>创建项目</label>
                </div>
                <div id="createProjectBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    <div class="form-group">
                        <label for="" class="control-label">项目名称：</label>
                        <p>
                            <input type="text" name="create_project_name" placeholder="项目名称"
                                   id="create_project_name"
                                   class="form-control">
                        </p>
                    </div>
                    <div class="form-group">
                        <label for="" class="control-label">代理机构：</label>
                        <select name="agent_name" id="agent_name" class="form-control">
                            {% for agency in agency_list %}
                                <option value="{{ agency.id }}">{{ agency.agent_name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="" class="control-label">截止时间：</label>
                        <p>
                            <input type="text" name="deadline_time" id="deadline_time" class="form-control"
                                   autocomplete="off">
                        </p>
                    </div>
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="create_project()"
                            data-dismiss="modal">确认
                    </button>

                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--追加到项目-->
    <div class="modal fade" id="addToProjectMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>追加到项目</label>
                </div>
                <div id="addToProjectBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    <div class="form-group">
                        <label for="" class="control-label">项目名称：</label>
                        <select name="add_to_project_name" id="add_to_project_name" class="form-control">
                            {% for project in project_list %}
                                <option value="{{ project.id }}">{{ project.project_name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="add_to_project()"
                            data-dismiss="modal">确认
                    </button>

                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出提示消息-->
    <div class="modal fade" id="disposalMessage" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="disposalMsgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    <h4 id="promptMessage">提示消息</h4>
                    <input style="width:400px;height:100px;display:none" type="text" id="feedbackMessage"
                           placeholder="">
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" data-dismiss="modal" id="confirm_button">确认
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>

    <!--抽检比例-->
    <div class="modal fade" id="spot_check" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="SpotCkeckMsgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    未检测到抽检记录 <br>
                    请输入抽检比例（10为全部）
                    <input type="number" οninput="if(value>10)value=10;if(value<1)value=1" name="spot_ratio"
                           id="spot_ratio"
                           class="config-input" autocomplete="off">
                    <!--                    <input type="hidden" name="spot_project_id" id="spot_project_id" value="">-->
                    <!--                    <input type="hidden" name="spot_is_modify" id="spot_is_modify" value="">-->
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="CreateSpotRecord()" data-dismiss="modal">
                        确认
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!--start 任务提交质检确认-->
    <div class="modal fade" id="submit_inspection_verify" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>任务提交质检确认</label>
                </div>
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    全部已合格任务{{ counts.5.num }}笔，已选
                    <input id="sv_count" type="text" value="0"
                           style="background: none; border: none; outline: none; width: 35px">
                    <input type="hidden" id="sv_ids">
                    笔任务，是否确认提交质检？
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        取消提交
                    </button>
                    <button type="button" class="btn btn-default" onclick="_submit_inspection()"
                            data-dismiss="modal">确定提交
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--end 任务提交质检确认-->

    <input id="taskIds" value="" style="display:none;"></input>
    <input id="copy_text_input" type="text" value=""
           style="position: absolute; top: 0; left: 0; opacity: 0; z-index: -10">

    <script>
        // 左侧导航栏
        function changeColor(id, color) {
            $(id).parent().parent().addClass("active");
            $(id).children().css("color", color);
        }

        // 获取url参数值
        function GetQueryValue(queryName) {
            var query = decodeURI(window.location.search.substring(1));
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == queryName) {
                    return pair[1];
                }
            }
            return null;
        }

        changeColor("#maintain_" + "{{ manage_type }}", "#00FF7F");
    </script>
    <script>
        Vue.config.delimiters = ["[[", "]]"];
        var mainVue = new Vue({
            el: "#main",
            data: {
                page: 1,
                status: 1,
                limit: '{{ limit }}',
                searchForm: "",
                checkedAll: false,
                showMain: false,
                tableData: {},
                paginator: {},
                spot_check_info: {},
                message: "",
            },
            methods: {
                parseTime: function (timeStamp) {
                    if (!timeStamp) {
                        return ""
                    }
                    var newDate = new Date();
                    newDate.setTime(timeStamp * 1000);
                    return newDate.toLocaleDateString()
                },
                truncatechars: function (str, end) {
                    if (!str) {
                        return ""
                    }
                    if (end <= str.length) {
                        return str.slice(0, end) + '...'
                    } else {
                        return str
                    }
                },
                parseStatus: function (status) {
                    var statuses = {
                        1: {
                            name: "已回收"
                        },
                        2: {
                            name: "待分配"
                        },
                        3: {
                            name: "处理中"
                        },
                        4: {
                            name: "待审核"
                        },
                        5: {
                            name: "已合格"
                        },
                        6: {
                            name: "不合格"
                        },
                        9: {
                            name: "已结算"
                        },
                        11: {
                            name: "回收申请"
                        },
                        14: {
                            name: "已通过"
                        }
                    };
                    return statuses[status]["name"]
                },
                parse_is_submit_quality: function (is_submit_quality) {
                    if (is_submit_quality) {
                        return "是"
                    } else {
                        return "否"
                    }
                }
            },
        });

        // 任务查询展示
        function searchTasks(page = 1) {
            var filter_tasks_api = "{{ filter_tasks_api }}";
            var searchForm = $("#searchForm").serializeArray();
            var data = {"csrfmiddlewaretoken": "{{ csrf_token }}"};
            var data1 = ""
            $.each(searchForm, function () {
                data[this.name] = this.value;
            });
            data['manage_type'] = "{{ manage_type }}";
            data['page'] = page;
            if ("{{ status_id }}") {
                data['status_id'] = "{{ status_id }}"
            }
            if ("{{ project_id }}") {
                data['project_id'] = "{{ project_id }}"
            }
            if ("{{ is_modify }}") {
                data['is_modify'] = "{{ is_modify }}"
            }

            $.ajax({
                type: "POST",
                url: filter_tasks_api,
                data: data,
                success: function (response) {
                    if (response) {
                        mainVue.limit = response.limit;
                        mainVue.showMain = true;
                        // mainVue.limits = response.limits;
                        mainVue.tableData = response.tableData;
                        mainVue.paginator = response.paginator;
                        mainVue.message = response.message;
                        mainVue.spot_check_info = response.spot_check_info;
                        // mainVue.incomes = response.incomes;
                    } else {
                        mainVue.showMain = false;
                    }
                }
            })
        }

        searchTasks();

        // 任务查询展示
        function maintain_task_download() {
            var filter_tasks_api = "{{ filter_tasks_api }}";
            var searchForm = $("#searchForm").serializeArray();
            var data = {"csrfmiddlewaretoken": "{{ csrf_token }}"};
            $.each(searchForm, function () {
                data[this.name] = this.value;
            });
            data['manage_type'] = "{{ manage_type }}";
            if ("{{ status_id }}") {
                data['status_id'] = "{{ status_id }}"
            }
            if ("{{ project_id }}") {
                data['project_id'] = "{{ project_id }}"
            }
            if ("{{ is_modify }}") {
                data['is_modify'] = "{{ is_modify }}"
            }
            let urlParams = new URLSearchParams(data);
            console.log(urlParams.toString())
            window.open("http://wego.istarshine.com/maintain/task_download/?" + urlParams.toString())
        }

        // 验证是否同一批次   0 创建项目   1 添加到项目
        function verify_batch(flag = 0) {
            var _tids = [];
            var _batch_list = [];
            $("input[name='td_checkbox']:checked").each(
                function () {
                    _tids.push($(this).val());
                    _batch_list.push($(this).attr('class'))
                }
            );

            // 判断是否选中任务
            tids = _tids.join();
            if (tids.length === 0) {
                alert("您没有选中任务");
                return false;
            }

            // 判断所有任务是否同一批次
            batch_id = _batch_list[0];
            for (let i = 1; i < _batch_list.length; i++) {
                if (batch_id != _batch_list[i]) {
                    alert('已选任务不属于同一批次，无法创建项目!');
                    return false
                }
            }
            if (flag === 0) {
                $("#createProjectMessage").modal();
            } else if (flag === 1) {
                $("#addToProjectMessage").modal();
            }
        }

        // 创建项目api
        function create_project() {
            var create_project_name = $('#create_project_name').val();
            var agency_id = $("#agent_name").val();
            var deadline_time = $("#deadline_time").val();
            if (!create_project_name || !agency_id) {
                alert('未填写项目名称或代理名称');
                return false;
            }
            $.ajax({
                url: "{% url 'maintain:create_project_api' %}",
                type: "POST",
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    create_project_name: create_project_name,
                    agency_id: agency_id,
                    batch_id: batch_id,
                    tids: tids,
                    deadline_time: deadline_time
                },
                success: function (resp) {
                    alert(resp.message);
                    location.reload();
                }
            })
        }

        // 添加到项目api
        function add_to_project() {
            var add_to_project_id = $('#add_to_project_name').val();
            if (!add_to_project_id) {
                alert('未选择项目');
                return false;
            }
            $.ajax({
                url: "{% url 'maintain:add_to_project_api' %}",
                type: "POST",
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    add_to_project_id: add_to_project_id,
                    tids: tids
                },
                success: function (resp) {
                    alert(resp.message);
                    location.reload();
                }
            })
        }

        // 分配任务api
        function allocate(uid) {
            var _tids = [];
            $("input[name='td_checkbox']:checked").each(
                function () {
                    _tids.push($(this).val());
                }
            );
            if (!_tids) {
                alert('没有选中任务');
                return false;
            }
            var tids = _tids.join();
            uid = $("input[name='uid_radio']:checked").val();
            if (!uid) {
                alert('没有选中用户');
                return false;
            }
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids,
                    uid: uid
                }
            });
            $.post(
                "{% url 'maintain:maintain_task_allot_api' %}",
                function (response) {
                    alert(response.message);
                    location.reload();
                }
            );
        }

        // 翻页
        function toPage(flag) {
            var page;
            var limit = mainVue.limit;
            switch (flag) {
                case 'first':
                    page = 1;
                    break;
                case 'last':
                    page = mainVue.paginator.last;
                    break;
                case 'prev':
                    page = mainVue.paginator.current - 1;
                    break;
                case 'next':
                    page = mainVue.paginator.current + 1;
                    break;
                case 'judge':
                    page = $("#page-judge").val();
                    break;
                default:
                    page = 1;
            }
            if (!page || page < mainVue.paginator.first) {
                page = mainVue.paginator.first;
            } else if (page > mainVue.paginator.last) {
                page = mainVue.paginator.last;
            }
            searchTasks(page, limit);
        }

        function BubbleTooltip(type, task_id) {
            switch (type) {
                case 'qualified':
                    var change_status_api = "{% url 'maintain:qualified' %}";
                    $('#promptMessage').html("确定修改为合格吗？");
                    $('#confirm_button').attr("onclick", "changeStatus(" + task_id + ",'" + change_status_api + "')");
                    break;
                case 'disqualified':
                    var change_status_api = "{% url 'maintain:disqualified' %}";
                    $('#promptMessage').html("确定修改为不合格吗？");
                    $('#confirm_button').attr("onclick", "changeStatus(" + task_id + ",'" + change_status_api + "')");
                    $('#feedbackMessage').css("display", "block");
                    break;
                case 'pass':
                    var change_status_api = "{% url 'maintain:passed' %}";
                    $('#promptMessage').html("确定通过吗？");
                    $('#confirm_button').attr("onclick", "changeStatus(" + task_id + ",'" + change_status_api + "')");
                    break;
                case 'recycle':
                    var change_status_api = "{% url 'maintain:recycle' %}";
                    $('#promptMessage').html("确定回收吗？");
                    $('#confirm_button').attr("onclick", "changeStatus(" + task_id + ",'" + change_status_api + "')");
                    $('#feedbackMessage').css("display", "block");
                    break;
            }
            $('#disposalMessage').modal();
        }

        // 修改状态
        function changeStatus(task_id, change_status_api) {
            var feedbackMessage;
            if (change_status_api.indexOf('disqualified') != -1 || change_status_api.indexOf('recycle') != -1) {
                feedbackMessage = $("#feedbackMessage").val();
                if (!feedbackMessage) {
                    alert('未填写不合格原因');
                    return false;
                }
            }
            $.ajax({
                url: change_status_api,
                type: "POST",
                data: {
                    csrfmiddlewaretoken: "{{ csrf_token }}",
                    task_id: task_id,
                    feedbackMessage: feedbackMessage
                },
                success: function (resp) {
                    alert(resp.message);
                    location.reload();
                }
            })
        }

        // 选中全部
        function checkAll(obj) {
            if ($(obj).is(":checked")) {
                $("input[name='td_checkbox']").prop("checked", true);
            } else {
                $("input[name='td_checkbox']").prop("checked", false);
            }
        }

        // 选中一个
        function checkOne(obj) {
            if ($("input[name='th_checkbox_all']").is(":checked")) {
                $("input[name='th_checkbox_all']").prop("checked", false)
            } else {
                var unChecked = true;
                $("input[name='td_checkbox']").each(
                    function () {
                        if (!$(this).is(":checked")) {
                            unChecked = false;
                        }
                    }
                );
                if (unChecked) {
                    $("input[name='th_checkbox_all']").prop("checked", true)
                }
            }
        }

        function CreateSpotRecord() {
            var spot_ratio = $('#spot_ratio').val();
            $.ajax({
                type: "POST",
                url: "{% url 'maintain:create_spot_record' %}",
                data: {
                    project_id: "{{ project_id }}",
                    is_modify: "{{ is_modify }}",
                    spot_ratio: spot_ratio,
                    csrfmiddlewaretoken: "{{ csrf_token }}"
                },
                success: function (response) {
                    if (response.code == 0) {
                        window.location.reload();
                    } else {
                        alert(response.message)
                    }
                }
            })
        }

        function pass_all() {
            $.ajax({
                type: "POST",
                url: "{% url 'maintain:pass_all' %}",
                data: {
                    project_id: "{{ project_id }}",
                    is_modify: "{{ is_modify }}",
                    csrfmiddlewaretoken: "{{ csrf_token }}"
                },
                success: function (response) {
                    alert(response.message);
                }
            })
        }

        // 时间控件
        laydate.render({
            elem: '#deadline_time'
        });
        laydate.render({
            elem: '#test1',
            range: true
        });
        laydate.render({
            elem: '#test2'
            , range: true
        });
        laydate.render({
            elem: '#test3'
            , range: true
        });
        laydate.render({
            elem: '#test4'
            , range: true
        });
        laydate.render({
            elem: '#test5'
            , range: true
        });
    </script>
    <script>
        // 提交质检确认
        function submit_inspection() {
            var _tids = [];
            var _status_ids = [];
            var _is_submit_qualitys = [];
            $("input[name='td_checkbox']:checked").each(
                function () {
                    _status_ids.push($(this).attr('status_id'));
                    _is_submit_qualitys.push($(this).attr('is_submit_quality'));
                    _tids.push($(this).val());
                }
            );
            // 判断是否选中任务
            if (_tids.length === 0) {
                alert("您没有选中任务");
                return false;
            }
            for (let i = 0; i < _status_ids.length; i++) {
                if (_status_ids[i] != "已合格") {
                    alert("选择任务中包含不是已合格的任务");
                    return false
                }
            }
            //for (let i = 0; i < _is_submit_qualitys.length; i++) {
            //    if (_is_submit_qualitys[i] != "否") {
            //        alert("选择任务中包含已提交质检的任务");
            //        return false
            //    }
            //}
            $("#sv_count").val(_tids.length);
            $("#sv_ids").val(_tids.join());
            $("#submit_inspection_verify").modal();
        }

        function _submit_inspection() {
            var tids = $("#sv_ids").val().split(',');
            $.ajax({
                url: "/quality/SupplierMaintainQuality/SupplierAdminCreateQualityPackage/",
                type: "POST",
                contentType: 'application/json',
                dateType: "json",
                data: JSON.stringify({"id_list": tids}),
                success: function (data) {
                    alert(data.data);
                    {#location.reload();#}
                },
                error: function (data) {
                    alert(JSON.parse(JSON.stringify(data)));
                }
            })
        }

        // 复制
        function copy_text(text) {
            $("#copy_text_input").val(text);
            $("#copy_text_input").select();
            document.execCommand('Copy');
            alert('复制成功')
        }
    </script>
{% endblock section_content %}
